package service

import (
	"context"
	"ebip/internel/domain"
	"ebip/internel/repository/repo"
	"golang.org/x/crypto/bcrypt"
)

// @Description
// @Author 代码小学生王木木

type IUserSvc interface {
	CreateUser(ctx context.Context, user domain.UserInfoDM) (int64, error)
}

type userService struct {
	repo repo.IUserRepo
}

func NewUserService(repo repo.IUserRepo) IUserSvc {
	return &userService{repo: repo}
}

func (s *userService) CreateUser(ctx context.Context, user domain.UserInfoDM) (int64, error) {
	// 加密在这里做
	hash, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost)
	if err != nil {
		return 0, err
	}
	user.Password = string(hash)
	user.Nickname = "用户xxx"
	return s.repo.CreateUser(ctx, user)
}
